#include <Ds3Stream.hpp>

Modeling::Ds3Stream::~Ds3Stream()
{}

Modeling::Ds3Stream::Ds3Stream(std::string filename)
{
	if ( ( this->file = fopen(filename.c_str(), "r") ) == NULL ) {
		throw FileNotFoundException(filename + std::string(" No such file or directory."));
	}
}

size_t Modeling::Ds3Stream::write(Modeling::Scene* scene)
{
	return 0;
}

size_t Modeling::Ds3Stream::read(Modeling::Scene* scene)
{
	return 0;
	//std::map< std::string, Modeling::VisualMesh<Vector3f>* >* meshMap = node->getMeshMap();
	//std::map< std::string, Modeling::VisualMesh<Vector3f>* >::iterator meshIterator = meshMap->begin();
/*	
	fseek(nodeFile, 0, SEEK_END);
	int filelength = ftell(nodeFile);
	fseek(nodeFile, 0, SEEK_SET);
	
	unsigned short l_chunk_id; //Chunk identifier
	unsigned int l_chunk_lenght; //Chunk lenght
	unsigned int l_chunk_pos;
	
	while (ftell(nodeFile) < filelength )
	{
		fread( &l_chunk_id, sizeof(unsigned short), 1, nodeFile );
		fread( &l_chunk_lenght, sizeof(unsigned int), 1, nodeFile );
		
		switch (l_chunk_id)
		{
			case MAIN3DS:
			{}
			break;    
			
			case M3D_VERSION:
			{
				unsigned int val;
				fread( &val, sizeof(unsigned int), 1, nodeFile );
			}
			break;
			
			case EDIT3DS:
			{
				unsigned int Edit3ds_chunk_length = l_chunk_lenght;
				unsigned int Edit3ds_chunk_pos = ftell(nodeFile) - 6;
				
				unsigned short Edit3ds_sub_chunk_id;
				unsigned int Edit3ds_sub_chunk_lenght;
				
				while( ftell(nodeFile) < Edit3ds_chunk_pos + Edit3ds_chunk_length )
				{
					fread( &Edit3ds_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &Edit3ds_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );
					
					switch(Edit3ds_sub_chunk_id)
					{
						case EDIT_MATERIAL:
						{
							std::cout << "    EDIT_MATERIAL: 0xAFFF" << std::endl;
							///////////////////////////////////////////////////
							//readMaterialChunk(scene, Edit3ds_sub_chunk_lenght);
							///////////////////////////////////////////////////
						}
						break;
						
						case EDIT_CONFIG1:
						{
							std::cout << "    EDIT_CONFIG1: 0x0100" << std::endl;
							fseek(file, Edit3ds_sub_chunk_lenght-6, SEEK_CUR);
						}
						break;
						
						case EDIT_CONFIG2:
						{
							std::cout << "    EDIT_CONFIG2: 0x3D3E" << std::endl;
							fseek(file, Edit3ds_sub_chunk_lenght-6, SEEK_CUR);
						}
						break;
						
						case EDIT_OBJECT:
						{
							std::cout << "    EDIT_OBJECT: 0x4000" << std::endl;
							
							unsigned int EditObject_chunk_length = Edit3ds_sub_chunk_lenght;
							unsigned int EditObject_chunk_pos = ftell(nodeFile) - 6;
							
							unsigned short EditObject_sub_chunk_id;
							unsigned int EditObject_sub_chunk_lenght;
							
							/////////////////////////
							//Modeling::Camera* camera;
							/////////////////////////
							////////////////////////////////////////////////////
							//lectura de datos del chunck
							char l_char;
							std::string name;
							do {
								fread( &l_char, sizeof(char), 1, nodeFile );
								if (l_char != '\0') name += l_char;
							} while(l_char != '\0');
							////////////////////////////////////////////////////
							
							while( ftell(nodeFile) < EditObject_chunk_pos + EditObject_chunk_length )
							{
								fread( &EditObject_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
								fread( &EditObject_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );
								
								switch (EditObject_sub_chunk_id)
								{
									case OBJ_TRIMESH:
									{
										std::cout << "      OBJ_TRIMESH: 0x4100" << std::endl;
										
										unsigned int ObjTriMesh_chunk_length = EditObject_sub_chunk_lenght;
										unsigned int ObjTriMesh_chunk_pos = ftell(nodeFile) - 6;
										
										unsigned short ObjTriMesh_sub_chunk_id;
										unsigned int ObjTriMesh_sub_chunk_lenght;
										
										///////////////////////////////////////////////////// 
										//Modeling::VisualMesh<Vector3f>* mesh = meshIterator->second;
										//meshIterator++;
										/////////////////////////////////////////////////////
										
										/////////////////////////////////////////////////////
										Modeling::VisualMesh<Vector3f>* mesh = node->addMesh(name);
										/////////////////////////////////////////////////////
										
										while( ftell(nodeFile) < ObjTriMesh_chunk_pos + ObjTriMesh_chunk_length )
										{
											fread( &ObjTriMesh_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
											fread( &ObjTriMesh_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );
											
											switch (ObjTriMesh_sub_chunk_id)
											{
												case TRI_VERTEXL:
												{
													std::cout << "        TRI_VERTEXL: 0x4110" << std::endl;
													unsigned short l_qty; 
													fread (&l_qty, sizeof (unsigned short), 1, nodeFile);
													
													float x, y, z;
													for (int i=0; i<l_qty; i++)
													{
														fread (&x, sizeof(float), 1, nodeFile);
														fread (&y, sizeof(float), 1, nodeFile);
														fread (&z, sizeof(float), 1, nodeFile);
														
														mesh->addVertex(x, z,-y);
													}
													//fseek(nodeFile, ObjTriMesh_sub_chunk_lenght-6, SEEK_CUR);
												}        
												break;
												
												case TRI_VERTEXOPTIONS:
												{
													std::cout << "        TRI_VERTEXOPTIONS: 0x4111" << std::endl;
													fseek(nodeFile, ObjTriMesh_sub_chunk_lenght-6, SEEK_CUR);
												}        
												break;
												
												case TRI_MAPPINGCOORS:
												{
													std::cout << "        TRI_MAPPINGCOORS: 0x4140" << std::endl;
													
													unsigned short l_qty;
													fread( &l_qty, sizeof(unsigned short), 1, nodeFile );
													
													float u,v;
													for (int i=0; i<l_qty; i++)
													{
														fread( &u, sizeof(float), 1, nodeFile );
														fread( &v, sizeof(float), 1, nodeFile  );
														
														////////////////////////
														mesh->addMapCoord(u, v);
														////////////////////////
													}
												}        
												break;
												
												case TRI_MAPPINGSTANDARD:
												{
													std::cout << "        TRI_MAPPINGSTANDARD: 0x4170" << std::endl;
													fseek(nodeFile, ObjTriMesh_sub_chunk_lenght-6, SEEK_CUR);
												}        
												break;
												
												case TRI_LOCAL:
												{
													std::cout << "        TRI_LOCAL: 0x4160 b" << std::endl;
													float xf, yf, zf;
													float xu, yu, zu;
													float xr, yr, zr;
													float xp, yp, zp;
													
													fread( &xf, sizeof(float), 1, nodeFile );
													fread( &yf, sizeof(float), 1, nodeFile );
													fread( &zf, sizeof(float), 1, nodeFile );
													
													fread( &xu, sizeof(float), 1, nodeFile );
													fread( &yu, sizeof(float), 1, nodeFile );
													fread( &zu, sizeof(float), 1, nodeFile );
													
													fread( &xr, sizeof(float), 1, nodeFile );
													fread( &yr, sizeof(float), 1, nodeFile );
													fread( &zr, sizeof(float), 1, nodeFile );
													
													fread( &xp, sizeof(float), 1, nodeFile );
													fread( &yp, sizeof(float), 1, nodeFile );
													fread( &zp, sizeof(float), 1, nodeFile );
													
													Vector4f front( xf,  zf, -yf, 0.0f );
													Vector4f up   ( xr,  zr, -yr, 0.0f );
													Vector4f right(-xu, -zu,  yu, 0.0f );
													Vector4f pos  ( xp,  zp, -yp, 1.0f );
													
													Matrix4f localMatrix;
													localMatrix[0] = front;
													localMatrix[1] = up;
													localMatrix[2] = right;
													localMatrix[3] = pos;
                                                    
													for (unsigned int i=0 ; i<mesh->getVerticesQty() ; i++)
													{
														Vector3f* vert = mesh->getVertex(i);
														
														Vector4f vert4;
														vert4[0] = (*vert)[0];
														vert4[1] = (*vert)[1];
														vert4[2] = (*vert)[2];
														vert4[3] = 1.0f;
														
														Vector4f vert2 = localMatrix.inverse() * vert4;
														
														(*vert)[0] = vert2[0];
														(*vert)[1] = vert2[1];
														(*vert)[2] = vert2[2];
													}
													
													mesh->setLocalMatrix(localMatrix);
												}        
												break;
												
												case TRI_FACEL1:
												{
													std::cout << "        TRI_FACEL1: 0x4120" << std::endl;
													
													unsigned int TriFacel1_chunk_length = ObjTriMesh_sub_chunk_lenght;
													unsigned int TriFacel1_chunk_pos = ftell(nodeFile) - 6;
													
													unsigned short l_qty;
													unsigned short l_face_flags; //Flag that stores some face information
													
													fread( &l_qty, sizeof(unsigned short), 1, nodeFile );
													
													unsigned short a, b, c;
													for (int i=0; i<l_qty; i++)
													{
														fread( &a, sizeof(unsigned short), 1, nodeFile );
														fread( &b, sizeof(unsigned short), 1, nodeFile );
														fread( &c, sizeof(unsigned short), 1, nodeFile );
														fread( &l_face_flags, sizeof(unsigned short), 1, nodeFile );
														
														Vector3f* v1 = mesh->getVertex(a);
														Vector3f* v2 = mesh->getVertex(b);
														Vector3f* v3 = mesh->getVertex(c);
														
														/////////////////////////////
														mesh->addPolygon(v1, v2, v3);
														/////////////////////////////
														
														Vector2f* m1 = mesh->getMapCoord(a);
														Vector2f* m2 = mesh->getMapCoord(b);
														Vector2f* m3 = mesh->getMapCoord(c);
														
														/////////////////////////////////////
														mesh->getPolygon(i)->addMapCoord(m1);
														mesh->getPolygon(i)->addMapCoord(m2);
														mesh->getPolygon(i)->addMapCoord(m3);
														/////////////////////////////////////
													}
													
													unsigned short TriFacel1_sub_chunk_id;
													unsigned int TriFacel1_sub_chunk_lenght;
													
													while( ftell(nodeFile) < TriFacel1_chunk_pos + TriFacel1_chunk_length )
													{
														fread( &TriFacel1_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
														fread( &TriFacel1_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );
														
														switch (TriFacel1_sub_chunk_id)
														{
															case TRI_MATERIAL:
															{
																std::cout << "          TRI_MATERIAL: 0x4130" << std::endl;
																
																char character;
																std::string matName;
																do {
																	fread( &character, sizeof(char), 1, nodeFile );
																	if (character != '\0') matName += character;
																} while(character != '\0');
																
																//First there is the material's name
																Modeling::Material* mat = node->getMaterial(matName);
																
																unsigned short val;
																fread( &val, sizeof(unsigned short), 1, nodeFile );
																
																//Then the faces wich has that material
																unsigned short face;
																for (int i=0 ; i<val ; i++)
																{
																	fread( &face, sizeof(unsigned short), 1, nodeFile );
																	mesh->getPolygon(face)->setMaterial(mat);
																}
															}
															break;
															
															case TRI_SMOOTH:
															{
																unsigned int group;
																for (int i=0 ; i<mesh->getPolygonsQty() ; i++)
																{
																	fread( &group, sizeof(unsigned int), 1, nodeFile );
																	mesh->getPolygon(i)->setSmoothGroup(group);
																}
																mesh->generateSmoothNormals();
																mesh->SetConnectivity();
																
																std::cout << "          TRI_SMOOTH: 0x4150" << std::endl;                                                              
															}
															break;
															
															default:
															{
																std::cout << "          TRI_FACEL1 default:" << (void*)TriFacel1_sub_chunk_id << std::endl;
																fseek(nodeFile, TriFacel1_sub_chunk_lenght-6, SEEK_CUR);
															}
															break;
														}//switch (TriFacel1_sub_chunk_id)
													}//while( ftell(l_file) < TriFacel1_chunk_pos + TriFacel1_chunk_length )
												}//case TRI_FACEL1:
												break;
												
												default:
												{
													std::cout << "        OBJ_TRIMESH default:" << (void*)ObjTriMesh_sub_chunk_id << std::endl;
													fseek(nodeFile, ObjTriMesh_sub_chunk_lenght-6, SEEK_CUR);
												}
												break;
											}//switch (ObjTriMesh_sub_chunk_id)
										}//while( ftell(l_file) < ObjTriMesh_chunk_pos + ObjTriMesh_chunk_length )
									}//case OBJ_TRIMESH:
									break;
									
									case OBJ_LIGHT:
									{
										std::cout << "      OBJ_LIGHT: 0x4600" << std::endl;
										
										unsigned int ObjLight_chunk_length = EditObject_sub_chunk_lenght;
										unsigned int ObjLight_chunk_pos = ftell(nodeFile) - 6;
										
										unsigned short ObjLight_sub_chunk_id;
										unsigned int ObjLight_sub_chunk_lenght;
										
										//////////////////////////////////////////////
										Modeling::Light* light = node->addLight(name);
										//////////////////////////////////////////////
										
										float x, y, z;
										fread( &x, sizeof(float), 1, nodeFile );
										fread( &y, sizeof(float), 1, nodeFile );
										fread( &z, sizeof(float), 1, nodeFile );
										
										/////////////////////////////
										light->setPosition(x, z, -y);
										/////////////////////////////
										
										while( ftell(nodeFile) < ObjLight_chunk_pos + ObjLight_chunk_length )
										{
											fread( &ObjLight_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
											fread( &ObjLight_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );
											
											switch (ObjLight_sub_chunk_id)
											{
												case COL_RGB:
												{
													std::cout << "        COL_RGB: 0x0010" << std::endl;
													
													RGBf rgb;
													fread( &rgb, sizeof(RGBf), 1, nodeFile );
													
													/////////////////////////////
													light->setAmbientColor(rgb);
													light->setDiffuseColor(rgb);
													light->setSpecularColor(rgb);
													/////////////////////////////
												}
												break;
												
												case FAR_ATTENUATION_END:
												{
													std::cout << "        FAR_ATTENUATION_END: 0x465A" << std::endl;
													float value;
													fread( &value, sizeof(float), 1, nodeFile );
													///////////////////////////////////
													light->setFarAttenuationEnd(value);
													///////////////////////////////////
												}
												break;
												
												case FAR_ATTENUATION_START:
												{
													std::cout << "        FAR_ATTENUATION_START: 0x465A" << std::endl;
													float value;
													fread( &value, sizeof(float), 1, nodeFile );
													/////////////////////////////////////
													light->setFarAttenuationStart(value);
													/////////////////////////////////////
												}
												break;
												
												case LIT_MULTIPLIER:
												{
													std::cout << "        LIT_MULTIPLIER: 0x465B" << std::endl;
													float multiplier;
													fread( &multiplier, sizeof(float), 1, nodeFile );
													/////////////////////////////////
													light->setMultiplier(multiplier);
													/////////////////////////////////
												}
												break;
												
												case COL_TRU:
												{
													std::cout << "        COL_TRU: 0x0011" << std::endl;
													//unsigned char R, G, B, A=1;
													fseek(nodeFile, ObjLight_sub_chunk_lenght-6, SEEK_CUR);
												}
												break;

												case LIT_SPOT:
												{
													std::cout << "        LIT_SPOT: 0x4610" << std::endl;
													
													float tx, ty, tz, hotspot, falloff;
													
													fread( &x, sizeof(float), 1, nodeFile );
													fread( &y, sizeof(float), 1, nodeFile );
													fread( &z, sizeof(float), 1, nodeFile );
													fread( &hotspot, sizeof(float), 1, nodeFile );
													fread( &falloff, sizeof(float), 1, nodeFile );
													
													//////////////////////////////
													light->setTarget(tx, tz, -ty);
													light->setHotspot(hotspot);
													light->setFalloff(falloff);
													//////////////////////////////
												}
												break;
												
												case SPOT_ROLL:
												{
													std::cout << "        SPOT_ROLL: 0x4656" << std::endl;
													float roll;
													fread( &roll, sizeof(float), 1, nodeFile );
												}
												break;
												
												case LOCAL_SHADOW2:
												{
													std::cout << "        LOCAL_SHADOW2: 0x4641" << std::endl;
													fseek(nodeFile, ObjLight_sub_chunk_lenght-6, SEEK_CUR);
												}
												break;
												
												case RAY_BIAS:
												{
													std::cout << "        RAY_BIAS: 0x4658" << std::endl;
													fseek(nodeFile, ObjLight_sub_chunk_lenght-6, SEEK_CUR);
												}
												break;
												
												case LIT_OFF:
												{
													std::cout << "        LIT_OFF: 0x4620" << std::endl;
													fseek(nodeFile, ObjLight_sub_chunk_lenght-6, SEEK_CUR);
												}
												break;
												
												default:
												{
													std::cout << "        OBJ_LIGHT default: " << (void*)ObjLight_sub_chunk_id << std::endl;
													fseek(nodeFile, ObjLight_sub_chunk_lenght-6, SEEK_CUR);
												}
												break;
											}//switch (ObjLight_sub_chunk_id)
										}//while( ftell(l_file) < ObjLight_chunk_pos + ObjLight_chunk_length )
									}//case OBJ_LIGHT:
									break;
									
									case OBJ_CAMERA:
									{
										std::cout << "      OBJ_CAMERA: 0x4700" << std::endl;
										
										/////////////////////////////////////////////////
										camera = node->addCamera(name);
										/////////////////////////////////////////////////
										
										float x, y, z, tx, ty, tz, angle, lens;
										
										fread( &x, sizeof(float), 1, nodeFile );
										fread( &y, sizeof(float), 1, nodeFile );
										fread( &z, sizeof(float), 1, nodeFile );
										
										fread( &tx, sizeof(float), 1, nodeFile );
										fread( &ty, sizeof(float), 1, nodeFile );
										fread( &tz, sizeof(float), 1, nodeFile );
										
										fread( &angle, sizeof(float), 1, nodeFile );
										fread( &lens, sizeof(float), 1, nodeFile );
										
										Vector3f pos(x, z, -y);
										Vector3f targ(tx, tz, -ty);
										
										/////////////////////////
										camera->setPosition(pos);
										camera->setTarget(targ);
										camera->setAngle(angle);
										camera->setLens(lens);
										/////////////////////////
									}
									break;
									
									case CAM_RANGES:
									{
										std::cout << "      CAM_RANGES: 0x4720" << std::endl;
										
										float near, far;
										
										fread( &near, sizeof(float), 1, nodeFile );
										fread( &far, sizeof(float), 1, nodeFile );
										
										///////////////////////////
										camera->setNearRange(near);
										camera->setFarRange(far);
										///////////////////////////
									}
									break;
									
									default:
									{
										std::cout << "      EDIT_OBJECT default: " << (void*)EditObject_sub_chunk_id << std::endl;
										fseek(nodeFile, EditObject_sub_chunk_lenght-6, SEEK_CUR);
									}
									break;
								}//switch (EditObject_sub_chunk_id)
							}//while( ftell(l_file) < EditObject_chunk_pos + EditObject_chunk_length )
						}//case EDIT_OBJECT:
						break;
						
						default:
						{
							std::cout << "    EDIT3DS default: " << (void*)Edit3ds_sub_chunk_id << std::endl;
							fseek(nodeFile, Edit3ds_sub_chunk_lenght-6, SEEK_CUR);
						}
						break;
					}//switch (Edit3ds_sub_chunk_id)
				}//while ( ftell(l_file) < Edit3ds_chunk_pos + Edit3ds_chunk_length )
			}//case EDIT3DS:
			break;
			
			case KEYF3DS:
			{
				std::cout << "KEYF3DS: 0xB000" << std::endl;
				///////////////////////////////////////////////////
				readKeyFramerChunk(node, nodeFile, l_chunk_lenght);
				///////////////////////////////////////////////////
			}
			break;
			
			default:
			{
				std::cout << "default: " << (void*)l_chunk_id << std::endl;
				fseek(nodeFile, l_chunk_lenght-6, SEEK_CUR);
			}
			break;
		} 
	}
    
	fclose(nodeFile); // Closes the file stream	
}

void Modeling::VisualNode::readMaterialChunk(Modeling::VisualNode* node, FILE* nodeFile, unsigned int EditMaterial_chunk_length)
{
	/////////////////////////////
	Modeling::Material* material;
	/////////////////////////////
    
    unsigned int EditMaterial_chunk_pos = ftell(nodeFile) - 6;
              
    unsigned short EditMaterial_sub_chunk_id;
    unsigned int EditMaterial_sub_chunk_lenght;

    while( ftell(nodeFile) < EditMaterial_chunk_pos + EditMaterial_chunk_length )
    {
	    fread( &EditMaterial_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
		fread( &EditMaterial_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

		switch(EditMaterial_sub_chunk_id)
        {
            case MAT_NAME01: 
            {
                char l_char;
				std::string name;
                do {
					fread( &l_char, sizeof(char), 1, nodeFile );
					if (l_char != '\0') name += l_char;
                } while(l_char != '\0');
                
                ///////////////////////////////////
                material = node->addMaterial(name);
				///////////////////////////////////
            }
            break; 

            case MAT_AMBIENT:
            {
				unsigned int MatAmbient_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatAmbient_chunk_pos = ftell(nodeFile) - 6;

                unsigned short MatAmbient_sub_chunk_id;
                unsigned int MatAmbient_sub_chunk_lenght;

                while( ftell(nodeFile) < MatAmbient_chunk_pos + MatAmbient_chunk_length )
                {
					fread( &MatAmbient_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatAmbient_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatAmbient_sub_chunk_id)
                    {
                        case MAT_RGB1:
                        {
                            RGBuc rgb;
							fread( &rgb, sizeof(RGBuc), 1, nodeFile );
							///////////////////////////////
							material->setAmbientColor(rgb);
							///////////////////////////////

						} 
                        break;    
                                                
                        default:
                        {
							std::cout << "        MAT_AMBIENT default: " << (void*)MatAmbient_sub_chunk_id << std::endl;
							fseek(nodeFile, MatAmbient_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break;
                    }//switch (MatAmbient_sub_chunk_id)
                }//while( ftell(l_file) < MatAmbient_chunk_pos + MatAmbient_chunk_length )
            }//case MAT_AMBIENT:
            break; 
                                    
            case MAT_DIFFUSE:
            {
				unsigned int MatDiffuse_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatDiffuse_chunk_pos = ftell(nodeFile) - 6;
              
                unsigned short MatDiffuse_sub_chunk_id;
                unsigned int MatDiffuse_sub_chunk_lenght;
                            
                while( ftell(nodeFile) < MatDiffuse_chunk_pos + MatDiffuse_chunk_length )
                {
					fread( &MatDiffuse_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatDiffuse_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatDiffuse_sub_chunk_id)
                    {
                        case MAT_RGB1:
                        {
							RGBuc rgb;
							fread( &rgb, sizeof(RGBuc), 1, nodeFile );
							///////////////////////////////
							material->setDiffuseColor(rgb);
							///////////////////////////////
                        }
                        break;    
                                                
                        default:
                        {
							std::cout << "        MAT_DIFFUSE default: " << (void*)MatDiffuse_sub_chunk_id << std::endl;
							fseek(nodeFile, MatDiffuse_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatDiffuse_sub_chunk_id)
                }//while( ftell(l_file) < MatDiffuse_chunk_pos + MatDiffuse_chunk_length )
            }//case MAT_DIFFUSE:
            break; 
                                    
            case MAT_SPECULAR:
            {
				unsigned int MatSpecular_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatSpecular_chunk_pos = ftell(nodeFile) - 6;
              
                unsigned short MatSpecular_sub_chunk_id;
                unsigned int MatSpecular_sub_chunk_lenght;
                            
                while( ftell(nodeFile) < MatSpecular_chunk_pos + MatSpecular_chunk_length )
                {
					fread( &MatSpecular_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatSpecular_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatSpecular_sub_chunk_id)
                    {
                        case MAT_RGB1:
                        {
							RGBuc rgb;
							fread( &rgb, sizeof(RGBuc), 1, nodeFile );
							///////////////////////////////
							material->setSpecularColor(rgb);
							///////////////////////////////
                        } 
                        break;    
                                                
                        default:
                        {
							std::cout << "        MAT_SPECULAR default: " << (void*)MatSpecular_sub_chunk_id << std::endl;
							fseek(nodeFile, MatSpecular_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatDiffuse_sub_chunk_id)
                }//while( ftell(l_file) < MatDiffuse_chunk_pos + MatDiffuse_chunk_length )
            }//case MAT_SPECULAR:
            break;
                                    
            case MAT_GLOSSINESS:
            {
				//std::cout << "      MAT_GLOSSINESS: 0xA040" << std::endl;

                unsigned int MatShininess_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatShininess_chunk_pos = ftell(nodeFile) - 6;
              
                unsigned short MatShininess_sub_chunk_id;
                unsigned int MatShininess_sub_chunk_lenght;
                            
                while( ftell(nodeFile) < MatShininess_chunk_pos + MatShininess_chunk_length )
                {
					fread( &MatShininess_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatShininess_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatShininess_sub_chunk_id)
                    {
                        case DOUBLE_BYTE:
                        {
							unsigned short glossiness;
							fread( &glossiness, sizeof(unsigned short), 1, nodeFile );
							////////////////////////////////////
							material->setGlossiness(glossiness);
							////////////////////////////////////
                        } 
                        break;    
                                                
                        default:
                        {
							std::cout << "        MAT_GLOSSINESS default: " << (void*)MatShininess_sub_chunk_id << std::endl;
							fseek(nodeFile, MatShininess_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatShininess_sub_chunk_id)
                }//while( ftell(l_file) < MatShininess_chunk_pos + MatShininess_chunk_length )
            }//case MAT_SHININESS:
            break;
                                    
            case MAT_SPECULAR_LEVEL:
            {
				unsigned int MatShinStrenght_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatShinStrenght_chunk_pos = ftell(nodeFile) - 6;
              
                unsigned short MatShinStrenght_sub_chunk_id;
                unsigned int MatShinStrenght_sub_chunk_lenght;
                            
                while( ftell(nodeFile) < MatShinStrenght_chunk_pos + MatShinStrenght_chunk_length )
                {
					fread( &MatShinStrenght_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatShinStrenght_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatShinStrenght_sub_chunk_id)
                    {
                        case DOUBLE_BYTE:
                        {
							unsigned short specularLevel;
							fread( &specularLevel, sizeof(unsigned short), 1, nodeFile );
							//////////////////////////////////////////
							material->setSpecularLevel(specularLevel);
							//////////////////////////////////////////
                        } 
                        break;    
                                                
                        default:
                        {
							std::cout << "        MAT_SPECULAR_LEVEL default: " << (void*)MatShinStrenght_sub_chunk_id << std::endl;
							fseek(nodeFile, MatShinStrenght_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatShinStrenght_sub_chunk_id)
                }//while( ftell(l_file) < MatShinStrenght_chunk_pos + MatShinStrenght_chunk_length )
            }
            break;
                                    
            case MAT_TRANSPARENCY:
            {
				unsigned int MatTransparency_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatTransparency_chunk_pos = ftell(nodeFile) - 6;
              
                unsigned short MatTransparency_sub_chunk_id;
                unsigned int MatTransparency_sub_chunk_lenght;
                            
                while( ftell(nodeFile) < MatTransparency_chunk_pos + MatTransparency_chunk_length )
                {
					fread( &MatTransparency_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatTransparency_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatTransparency_sub_chunk_id)
                    {
                        case DOUBLE_BYTE:
                        {
							unsigned short transparency;
							fread( &transparency, sizeof(unsigned short), 1, nodeFile );
							////////////////////////////////////////
							material->setTransparency(transparency);
							////////////////////////////////////////
                        } 
                        break;    
                                                
                        default:
                        {
							std::cout << "        MAT_TRANSPARENCY default: " << (void*)MatTransparency_sub_chunk_id << std::endl;
							fseek(nodeFile, MatTransparency_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatTransparency_sub_chunk_id)
                }//while( ftell(l_file) < MatTransparency_chunk_pos + MatTransparency_chunk_length )
            }     
            break; 
                                    
            case MAT_TRANSFALLOF:
            {
				unsigned int MatTransfallof_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatTransfallof_chunk_pos = ftell(nodeFile) - 6;
              
                unsigned short MatTransfallof_sub_chunk_id;
                unsigned int MatTransfallof_sub_chunk_lenght;
                            
                while( ftell(nodeFile) < MatTransfallof_chunk_pos + MatTransfallof_chunk_length )
                {
					fread( &MatTransfallof_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatTransfallof_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatTransfallof_sub_chunk_id)
                    {
                        case DOUBLE_BYTE:
                        {
							unsigned short transFalloff;
							fread( &transFalloff, sizeof(unsigned short), 1, nodeFile );
							////////////////////////////////////////
							material->setTransparencyFalloff(transFalloff);
							////////////////////////////////////////
                        }
                        break;    
                                                
                        default:
                        {
							std::cout << "        MAT_TRANSFALLOF default: " << (void*)MatTransfallof_sub_chunk_id << std::endl;
							fseek(nodeFile, MatTransfallof_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatTransfallof_sub_chunk_id)
                }//while( ftell(l_file) < MatTransfallof_chunk_pos + MatTransfallof_chunk_length )
            }     
            break; 
                                    
            case MAT_REFLECTBLUR:
            {
				unsigned int MatReflectblur_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatReflectblur_chunk_pos = ftell(nodeFile) - 6;
              
                unsigned short MatReflectblur_sub_chunk_id;
                unsigned int MatReflectblur_sub_chunk_lenght;
                            
                while( ftell(nodeFile) < MatReflectblur_chunk_pos + MatReflectblur_chunk_length )
                {
					fread( &MatReflectblur_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatReflectblur_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatReflectblur_sub_chunk_id)
                    {
                        case DOUBLE_BYTE:
                        {
							unsigned short val;
							fread( &val, sizeof(unsigned short), 1, nodeFile );
                        } 
                        break;    
                        
                        default:
                        {
							std::cout << "        MAT_REFLECTBLUR default: " << (void*)MatReflectblur_sub_chunk_id << std::endl;
							fseek(nodeFile, MatReflectblur_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatReflectblur_sub_chunk_id)
                }//while( ftell(l_file) < MatReflectblur_chunk_pos + MatReflectblur_chunk_length )
            }     
            break; 
            
            case MAT_MATERIALTYPE:
            {
				unsigned short val;
				fread( &val, sizeof(unsigned short), 1, nodeFile );
				bool faceted = (val == 1);
				//////////////////////////////
				material->setFaceted(faceted);
				//////////////////////////////
            }     
            break;
            
            case MAT_SELFILLUM:
            {
				unsigned int MatSelfilum_chunk_length = EditMaterial_sub_chunk_lenght;
                unsigned int MatSelfilum_chunk_pos = ftell(nodeFile) - 6;

                unsigned short MatSelfilum_sub_chunk_id;
                unsigned int MatSelfilum_sub_chunk_lenght;
    
                while( ftell(nodeFile) < MatSelfilum_chunk_pos + MatSelfilum_chunk_length )
                {
					fread( &MatSelfilum_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &MatSelfilum_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

                    switch (MatSelfilum_sub_chunk_id)
                    {
                        case DOUBLE_BYTE:
                        {
							unsigned short selfIlumination;
							fread( &selfIlumination, sizeof(unsigned short), 1, nodeFile );
							//////////////////////////////////////////////
							material->setSelfIlumination(selfIlumination);
							//////////////////////////////////////////////
                        } 
                        break;    
                        
                        default:
                        {
							std::cout << "        MAT_SELFILLUM default: " << (void*)MatSelfilum_sub_chunk_id << std::endl;
							fseek(nodeFile, MatSelfilum_sub_chunk_lenght-6, SEEK_CUR);
                        }
                        break; 
                    }//switch (MatSelfilum_sub_chunk_id)
                }//while( ftell(l_file) < MatSelfilum_chunk_pos + MatSelfilum_chunk_length )
            }     
            break;
            
            case MAT_TWOSIDED:
            {
                ////////////////////////////
				material->setTwoSided(true);
				////////////////////////////
            }     
            break;
            
            case MAT_WIREON:
            {
                /////////////////////////
				material->setWired(true);
				/////////////////////////
            }     
            break;
            
            case MAT_FACEMAP:
            {
                ///////////////////////////
				material->setFaceMap(true);
				///////////////////////////
            }     
            break;
            
            case MAT_TRANSFALLOFF_IN:
            {
				//////////////////////////////////
                material->setTransFalloffIn(true);
                //////////////////////////////////
            }     
            break;
            
            case MAT_WIRE_UNITS:
            {
				/////////////////////////////
				material->setWireUnits(true);
				/////////////////////////////
            }     
            break;
            
            case MAT_WIRE_SIZE:
            {
				float wireSize;
				fread( &wireSize, sizeof(float), 1, nodeFile );
				////////////////////////////////
				material->setWireSize(wireSize);
				////////////////////////////////
            }     
            break;
            
            case MAT_TRANSPADD:
            {
				/////////////////////////////////
				material->setTransAdditive(true);
				/////////////////////////////////
            }
            break;
            
            case DIFFUSE_MAP:
            {
				/////////////////////////////////////////////////
				material->enableDiffuseMap();
				Modeling::Mapp* mapp = material->getDiffuseMap();
				/////////////////////////////////////////////////
				Modeling::VisualNode::readMapChunk(mapp, nodeFile, EditMaterial_sub_chunk_lenght);
            }
            break;
            
            case OPACITY_MAP:
            {
				/////////////////////////////////////////////////
				material->enableOpacityMap();
				Modeling::Mapp* mapp = material->getOpacityMap();
				/////////////////////////////////////////////////
				Modeling::VisualNode::readMapChunk(mapp, nodeFile, EditMaterial_sub_chunk_lenght);
            }
            break;
            
            case BUMP_MAP:
            {
				//////////////////////////////////////////////
				material->enableBumpMap();
				Modeling::Mapp* mapp = material->getBumpMap();
				//////////////////////////////////////////////
				Modeling::VisualNode::readMapChunk(mapp, nodeFile, EditMaterial_sub_chunk_lenght);
            }
            break;
            
            case SPECULAR_MAP:
            {
				//////////////////////////////////////////////////
				material->enableSpecularMap();
				Modeling::Mapp* mapp = material->getSpecularMap();
				//////////////////////////////////////////////////
				Modeling::VisualNode::readMapChunk(mapp, nodeFile, EditMaterial_sub_chunk_lenght);
            }
            break;
            
            case GLOSSINESS_MAP:
            {
				////////////////////////////////////////////////////
				material->enableGlossinessMap();
				Modeling::Mapp* mapp = material->getGlossinessMap();
				////////////////////////////////////////////////////
				Modeling::VisualNode::readMapChunk(mapp, nodeFile, EditMaterial_sub_chunk_lenght);
            }
            break;
            
            case SELF_ILUM_MAP:
            {
				/////////////////////////////////////////////////////////
				material->enableSelfIluminationMap();
				Modeling::Mapp* mapp = material->getSelfIluminationMap();
				/////////////////////////////////////////////////////////
				Modeling::VisualNode::readMapChunk(mapp, nodeFile, EditMaterial_sub_chunk_lenght);
            }
            break;
            
            case REFLECTION_MAP:
            {
				////////////////////////////////////////////////////
				material->enableReflectionMap();
				Modeling::Mapp* mapp = material->getReflectionMap();
				////////////////////////////////////////////////////
				Modeling::VisualNode::readMapChunk(mapp, nodeFile, EditMaterial_sub_chunk_lenght);
            }
            break;
            
            default:
            {
				std::cout << "      EDIT_MATERIAL default: " << (void*)EditMaterial_sub_chunk_id << std::endl;
				fseek(nodeFile, EditMaterial_sub_chunk_lenght-6, SEEK_CUR);
            }
            break;
        }//switch(EditMaterial_sub_chunk_id)
    }//while( ftell(l_file) < EditMaterial_chunk_pos + EditMaterial_chunk_length )
}

void Modeling::VisualNode::readMapChunk(Modeling::Mapp* mapp, FILE* nodeFile, unsigned int Map_chunk_length)
{
    unsigned int Map_chunk_pos = ftell(nodeFile) - 6;
              
    unsigned short Map_sub_chunk_id;
    unsigned int Map_sub_chunk_lenght;
                            
    while( ftell(nodeFile) < Map_chunk_pos + Map_chunk_length )
    {
		fread( &Map_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
		fread( &Map_sub_chunk_lenght, sizeof(unsigned int), 1, nodeFile );

        switch (Map_sub_chunk_id)
        {
			case DOUBLE_BYTE:
			{
				unsigned short ammount;
				fread( &ammount, sizeof(unsigned short), 1, nodeFile );
				//////////////////////////
				mapp->setAmmount(ammount);
				//////////////////////////
            }     
			break;

            case MAP_FILENAME:
            {
                char l_char; 
				std::string filename;
                do {
					fread( &l_char, sizeof(char), 1, nodeFile );
					filename += l_char;
                } while(l_char != '\0');
                ////////////////////////////
                mapp->setFileName(filename);
                ////////////////////////////
            } 
            break;  

			case MAP_OPTIONS:
			{
				unsigned short options;
				fread( &options, sizeof(unsigned short), 1, nodeFile );
				//////////////////////////
				mapp->setOptions(options);
				//////////////////////////
            }     
			break;

			case MAP_BLUR:
			{
				float blur;
				fread( &blur, sizeof(float), 1, nodeFile );
				////////////////////
				mapp->setBlur(blur);
				////////////////////
            }     
			break;

			case TINT_FIRST_COLOR:
			{
				Vector3uc val;
				fread( &val, sizeof(Vector3uc), 1, nodeFile );
            }     
			break;

			case TINT_SECOND_COLOR:
			{
				Vector3uc val;
				fread( &val, sizeof(Vector3uc), 1, nodeFile );
            }     
			break;

			case R_CHANEL_COLOR:
			{
				Vector3uc val;
				fread( &val, sizeof(Vector3uc), 1, nodeFile );
            }     
			break;

			case G_CHANEL_COLOR:
			{
				Vector3uc val;
				fread( &val, sizeof(Vector3uc), 1, nodeFile );
            }     
			break;

			case B_CHANEL_COLOR:
			{
				Vector3uc val;
				fread( &val, sizeof(Vector3uc), 1, nodeFile );
            }     
			break;
						                        
			case U_OFFSET:
			{
				float uOffset;
				fread( &uOffset, sizeof(float), 1, nodeFile );
				//////////////////////////
				mapp->setUoffset(uOffset);
				//////////////////////////
            }     
			break;
						                        
			case V_OFFSET:
			{
				float vOffset;
				fread( &vOffset, sizeof(float), 1, nodeFile );
				//////////////////////////
				mapp->setVoffset(vOffset);
				//////////////////////////
            }     
			break;
						                        
			case U_SCALE:
			{
				float uScale;
				fread( &uScale, sizeof(float), 1, nodeFile );
				////////////////////////
				mapp->setUscale(uScale);
				////////////////////////
            }     
			break;
						                        
			case V_SCALE:
			{
				float vScale;
				fread( &vScale, sizeof(float), 1, nodeFile );
				////////////////////////
				mapp->setVscale(vScale);
				////////////////////////
            }     
			break;
						                        
			case MAP_ROTATION_ANGLE:
			{
				float rotationAngle;
				fread( &rotationAngle, sizeof(float), 1, nodeFile );
				//////////////////////////////////////
				mapp->setRotationAngle(rotationAngle);
				//////////////////////////////////////
            }     
			break;
						                        
            default:
            {
				std::cout << "MAP default: " << (void*)Map_sub_chunk_id << std::endl;
				fseek(nodeFile, Map_sub_chunk_lenght-6, SEEK_CUR);
            }
            break; 
        }//switch (Map_sub_chunk_id)
    }//while( ftell(nodeFile) < Map_chunk_pos + Map_chunk_length )
}

void Modeling::VisualNode::readKeyFramerChunk(Modeling::VisualNode* node, FILE* nodeFile, unsigned int Keyf3ds_chunk_length)
{
    unsigned int Keyf3ds_chunk_pos = ftell(nodeFile) - 6;
  
	unsigned short Keyf3ds_sub_chunk_id;
	unsigned int Keyf3ds_sub_chunk_length;
    
	while( ftell(nodeFile) < Keyf3ds_chunk_pos + Keyf3ds_chunk_length )
	{
		fread( &Keyf3ds_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
		fread( &Keyf3ds_sub_chunk_length, sizeof(unsigned int), 1, nodeFile );

		switch(Keyf3ds_sub_chunk_id)
		{
            case KEYF_HEADER:
            {
                std::cout << "  KEYF_HEADER: 0xB00A" << std::endl;
                unsigned short revision;
                unsigned int animlen;
                char ch;
                std::string name;
                
                fread(&revision, sizeof(unsigned short), 1, nodeFile);
                
                do {
                    fread(&ch, sizeof(char), 1, nodeFile);
                    if (ch != '\0') name += ch;
                }while (ch != '\0');
                
                fread(&animlen, sizeof(unsigned int), 1, nodeFile);
                
                //std::cout << "    revision: " << revision << std::endl;
                //std::cout << "    name: " << name << std::endl;
                //std::cout << "    animlen: " << animlen << std::endl;
            }
            break;
            
            case KEYF_FRAMES:
            {
                std::cout << "  KEYF_FRAMES: 0xB008" << std::endl;
                unsigned int start;
                unsigned int end;
                fread(&start, sizeof(unsigned int), 1, nodeFile);
                fread(&end, sizeof(unsigned int), 1, nodeFile);
                
                //std::cout << "    start: " << start << std::endl;
                //std::cout << "    end: " << end << std::endl;
            }
            break;
            
            case KEYF_CUR_FRAME:
            {
                std::cout << "  KEYF_CUR_FRAME: 0xB009" << std::endl;
                unsigned int curr;
                fread(&curr, sizeof(unsigned int), 1, nodeFile);
                //std::cout << "    curr: " << curr << std::endl;
            }
            break;
            
            case OBJECT_NODE_TAG:
            {
                std::cout << "  OBJECT_NODE_TAG: 0xB002" << std::endl;
                
                unsigned int NodeTag_chunk_length = Keyf3ds_sub_chunk_length;
				unsigned int NodeTag_chunk_pos = ftell(nodeFile) - 6;
              
				unsigned short NodeTag_sub_chunk_id;
				unsigned int NodeTag_sub_chunk_length;
                
				while( ftell(nodeFile) < NodeTag_chunk_pos + NodeTag_chunk_length )
				{
					fread( &NodeTag_sub_chunk_id, sizeof(unsigned short), 1, nodeFile );
					fread( &NodeTag_sub_chunk_length, sizeof(unsigned int), 1, nodeFile );

					switch(NodeTag_sub_chunk_id)
					{
                        case NODE_ID:
                        {
                            std::cout << "    NODE_ID: 0xB030 " << std::endl;
                            unsigned short id;
                            fread(&id, sizeof(unsigned short), 1, nodeFile);
                            std::cout << "    id: " << id << std::endl;
                        }
                        break;
                        
                        case KEYF_OBJHIERARCH:
                        {
                            std::cout << "    KEYF_OBJHIERARCH: 0xB010 " << std::endl;
                            unsigned short flag1;
                            unsigned short flag2;
                            short hierarchy;
                            char ch;
                            std::string name;
                            
                            do {
                                fread(&ch, sizeof(char), 1, nodeFile);
                                if (ch != '\0') name += ch;
                            } while(ch != '\0');
                            
                            fread(&flag1, sizeof(unsigned short), 1, nodeFile);
                            fread(&flag2, sizeof(unsigned short), 1, nodeFile);
                            fread(&hierarchy, sizeof(short), 1, nodeFile);
                            
                            std::cout << "      name: " << name << std::endl;
                            //std::cout << "      flag1: " << flag1 << std::endl;
                            //std::cout << "      flag2: " << flag2 << std::endl;
                            std::cout << "      hierarchy: " << hierarchy << std::endl;
                        }
                        break;
                        
                        case KEYF_PIVOT:
                        {
                            std::cout << "    KEYF_PIVOT: 0xB013" << std::endl;
                            float x, y, z;
                            fread(&x, sizeof(float), 1, nodeFile);
                            fread(&y, sizeof(float), 1, nodeFile);
                            fread(&z, sizeof(float), 1, nodeFile);
                            //std::cout << "      pivot: (" << x << ", " << y << ", " << z << ")" << std::endl;
                        }
                        break;
                        
                        case POSITION_TRACK_TAG:
                        {
                            std::cout << "    POSITION_TRACK_TAG: 0xB020" << std::endl;
                            
                            unsigned short flags;
                            unsigned short unknown[4];
                            unsigned short keys;
                            unsigned short unk;
                            
                            unsigned short framenum;
                            unsigned int unk2;
                            float x;
                            float y;
                            float z;
                            
                            fread(&flags, sizeof(unsigned short), 1, nodeFile);
                            fread(&unknown, sizeof(unsigned short), 4, nodeFile);
                            fread(&keys, sizeof(unsigned short), 1, nodeFile);
                            fread(&unk, sizeof(unsigned short), 1, nodeFile);
                            
                            std::cout << "      flags: " << flags << std::endl;
                            std::cout << "      unknown[0]: " << unknown[0] << std::endl;
                            std::cout << "      unknown[1]: " << unknown[1] << std::endl;
                            std::cout << "      unknown[2]: " << unknown[2] << std::endl;
                            std::cout << "      unknown[3]: " << unknown[3] << std::endl;
                            std::cout << "      keys: " << keys << std::endl;
                            std::cout << "      unk: " << unk << std::endl;
                            
                            for (unsigned short i=0 ; i<keys ; i++)
                            {
                                fread(&framenum, sizeof(unsigned short), 1, nodeFile);
                                fread(&unk2, sizeof(unsigned int), 1, nodeFile);
                                fread(&x, sizeof(float), 1, nodeFile);
                                fread(&y, sizeof(float), 1, nodeFile);
                                fread(&z, sizeof(float), 1, nodeFile);
                                //std::cout << "      unk2: " << unk2 << std::endl;
                                //std::cout << "      " << framenum << " pos (" << x << ", " << y << ", " << z << ")" << std::endl;
                            }
                        }
                        break;
                        
                        case ROTATION_TRACK_TAG:
                        {
                            std::cout << "    ROTATION_TRACK_TAG: 0xB021" << std::endl;
                            
                            unsigned short flags;
                            unsigned short unknown[4];
                            unsigned short keys;
                            unsigned short unk;
                            
                            unsigned short framenum;
                            unsigned int unk2;
                            float rotation;
                            float x;
                            float y;
                            float z;
                            
                            fread(&flags, sizeof(unsigned short), 1, nodeFile);
                            fread(&unknown, sizeof(unsigned short), 4, nodeFile);
                            fread(&keys, sizeof(unsigned short), 1, nodeFile);
                            fread(&unk, sizeof(unsigned short), 1, nodeFile);
                            
                            std::cout << "      flags: " << flags << std::endl;
                            std::cout << "      unknown[0]: " << unknown[0] << std::endl;
                            std::cout << "      unknown[1]: " << unknown[1] << std::endl;
                            std::cout << "      unknown[2]: " << unknown[2] << std::endl;
                            std::cout << "      unknown[3]: " << unknown[3] << std::endl;
                            std::cout << "      keys: " << keys << std::endl;
                            std::cout << "      unk: " << unk << std::endl;
                            
                            for (unsigned short i=0 ; i<keys ; i++)
                            {
                                fread(&framenum, sizeof(unsigned short), 1, nodeFile);
                                fread(&unk2, sizeof(unsigned int), 1, nodeFile);
                                fread(&rotation, sizeof(float), 1, nodeFile);
                                fread(&x, sizeof(float), 1, nodeFile);
                                fread(&y, sizeof(float), 1, nodeFile);
                                fread(&z, sizeof(float), 1, nodeFile);
                                //std::cout << "      unk2: " << unk2 << std::endl;
                                //std::cout << "      rotation: " << rotation << std::endl;
                                //std::cout << "      " << framenum << " rot (" << x << ", " << y << ", " << z << ")" << std::endl;
                            }
                        }
                        break;
                        
                        case SCALE_TRACK_TAG:
                        {
                            std::cout << "    SCALE_TRACK_TAG: 0xB022" << std::endl;
                            
                            //std::cout << "      len: " << NodeTag_sub_chunk_length-6 << std::endl;
                            fseek(nodeFile, NodeTag_sub_chunk_length-6, SEEK_CUR);
                        }
                        break;
                        
                        default:
                        {
                            std::cout << "    OBJECT_NODE_TAG: default " << (void*)NodeTag_sub_chunk_id << std::endl;
                            fseek(nodeFile, NodeTag_sub_chunk_length-6, SEEK_CUR);
                        }
                        break;
                    }
                }
            }
            break;
            
            default:
            {
                std::cout << "  KEYF3DS: default " << (void*)Keyf3ds_sub_chunk_id << std::endl;
                fseek(nodeFile, Keyf3ds_sub_chunk_length-6, SEEK_CUR);
            }
            break;
            
        }
    }
*/
}



